"""
保险产品数据库模型
"""
import uuid

from tortoise import Model, fields


class Products(Model):
    product_id = fields.CharField(pk=True, default=lambda: str(uuid.uuid4())[:15],
                                  generated=False, max_length=15,
                                  unique=True, description="保险产品编号")
    product_name = fields.CharField(max_length=128, description="保险产品名称")
    # 创建保险产品时，需要选择保险公司,这个是外键
    company = fields.ForeignKeyField('models.InsuranceCompany', max_length=15,
                                     related_name='products', description="保险公司编号")
    status = fields.BooleanField(default=True, description="保险产品状态")
    created_at = fields.DatetimeField(auto_now_add=True, description="创建时间")
    updated_at = fields.DatetimeField(auto_now=True, description="更新时间")

    class Meta(Model.Meta):
        table = "products"
        table_description = "保险产品表"
        ordering = ["-updated_at"]
